<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>权限节点规则列表-后台管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="__STATIC__/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="__STATIC__/css/main.css?v={:time()}" media="all">
    <link rel="stylesheet" href="__STATIC__/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <script src="__STATIC__/js/jquery-1.8.3.min.js"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style id="LM-bg-color">
    </style>
</head>
<div class="LM-container">
    <div class="LM-main">
        <div class="admin-main layui-anim layui-anim-upbit">
            <fieldset class="layui-elem-field layui-field-title">
                <legend>权限节点规则列表</legend>
            </fieldset>
            <blockquote class="layui-elem-quote">
                <a href="{:url('Add')}" class="layui-btn layui-btn-sm LM-add">添加权限节点规则</a>
                <a class="layui-btn layui-btn-normal layui-btn-sm" onclick="openAll();">展开或折叠全部</a>
            </blockquote>
            <table class="layui-table" id="treeGrid" lay-filter="treeGrid"></table>
        </div>
    </div>
</div>

<script type="text/html" id="auth">
    <input type="checkbox" name="auth_open" data-href="{:url('open')}?id={{d.id}}" value="{{d.id}}" lay-skin="switch" lay-text="是|否" lay-filter="switchStatus" {{ d.auth_open == 1 ? 'checked' : '' }}>
</script>
<script type="text/html" id="status">
    <input type="checkbox" name="status" data-href="{:url('setstate')}?id={{d.id}}" value="{{d.id}}" lay-skin="switch" lay-text="显示|隐藏" lay-filter="switchStatus" {{ d.status==1 ? 'checked' : '' }}>
</script>
<script type="text/html" id="order">
    <input name="{{d.id}}" data-id="{{d.id}}" class="list_order layui-input" value=" {{d.sort}}" size="10"/>
</script>
<script type="text/html" id="icon">
    <span class="icon {{d.icon}}"></span>
</script>
<script type="text/html" id="action">
    <a href="{:url('add')}?id={{d.id}}" class="layui-btn layui-btn-sm layui-btn-normal" lay-event="add"><i class="layui-icon">&#xe61f;</i>添加子级权限</a>
    <a href="{:url('edit')}?id={{d.id}}" class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe642;</i>编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-sm" onclick="ruledel(this)" href="javascript:;" url="{:url('ruledel')}?rule_id={{d.id}}"><i class="layui-icon">&#xe640;</i>删除</a>
</script>


<script src="__STATIC__/layui/layui.js" charset="utf-8"></script>
<script src="__STATIC__/common.js"></script>
<script>
    var editObj=null,ptable=null,treeGrid=null,tableId='treeGrid',layer=null;
    layui.config({
        base: '__STATIC__/layui/extend/'
    }).extend({
        treeGrid: 'treeGrid/treeGrid'
    }).use(['jquery','treeGrid','layer','form'], function(){
        var $=layui.jquery ,form = layui.form;
        treeGrid = layui.treeGrid;
        layer=layui.layer;

        ptable=treeGrid.render({
            id:tableId
            ,elem: '#'+tableId
            ,idField:'id'
            ,url:'{:url("index")}'
            ,cellMinWidth: 100
            ,treeId:'id'//树形id字段名称
            ,treeUpId:'pid'//树形父id字段名称
            ,treeShowName:'title'//以树形式显示的字段
            ,height:'full-140'
            ,isFilter:false
            ,iconOpen:true//是否显示图标【默认显示】
            ,isOpenDefault:true//节点默认是展开还是折叠【默认展开】
            ,cols: [[
                {field: 'id', title: 'ID', width: '5%', fixed: true},
                {field: 'icon', align: 'center',title: 'Icon', width: '10%',templet: '#icon'},
                {field: 'title', title: '权限名称', width: '20%'},
                {field: 'name', title: '控制器/方法', width: '13%'},
                {field: 'auth_open',align: 'center', title: '是否验证权限',width: '10%',toolbar: '#auth'},
                {field: 'status',align: 'center',title: '菜单状态', width: '10%',toolbar: '#status'},
                {field: 'sort',align: 'center', title: '排序', width: '8%', templet: '#order'},
                {title:'操作',width:'25%', toolbar: '#action',align:"center"},
            ]]
            ,page:false
        });



        $('body').on('blur','.list_order',function() {
            var id = $(this).attr('data-id');
            var sort = $(this).val();
            $.post('{:url("sort")}',{id:id,sort:sort},function(res){
                if(res.code > 0){
                    layer.msg(res.msg,{time:1000,icon:1},function(){
                        location.href = res.url;
                    });
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                    treeGrid.render;
                }
            })
        })
    });

    function openAll() {
        var treedata=treeGrid.getDataTreeList(tableId);
        treeGrid.treeOpenAll(tableId,!treedata[0][treeGrid.config.cols.isOpen]);
    }

    function ruledel(obj){
        var url = $(obj).attr('url');
        //alert(url);
        layer.confirm('确认要删除吗？',function(index){

            $.ajax({
                type: 'POST',
                url: url,
                data: {'id':url},
                dataType: 'json',
                success: function(data){
                    if(data.status==200){
                        layer.msg(data.msg, {icon: 1, time: 1000}, function(){
                            location.href = data.url;
                        });
                    }
                },
            });
        });
    }

</script>
</body>
</html>